//
//  String+saveFilePath.swift
//  Weibo
//
//  Created by zxy on 2018/12/7.
//  Copyright © 2018 zxy. All rights reserved.
//

import Foundation
extension String{
    
    //使用：“abc”.documentDir
    
    ///返回doucument文件路径
    ///
    /// - Returns: doucument文件路径
    func documentDir() ->String{
        let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).last!
        //在这里加lastPathComponent目的是如果是如果是网页链接如：http:www.baidu.com/aa.png,直接取最后文件名进行保存
        let filePath = (path as NSString).appendingPathComponent((self as NSString).lastPathComponent)
        return filePath
    }
    

    ///返回cache文件路径
    ///
    /// - Returns:  cache文件路径
    func cacheDir() ->String{
        let path = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).last!
        let filePath = (path as NSString).appendingPathComponent((self as NSString).lastPathComponent)
        return filePath
    }
    
    func tmpDir() ->String{
        let path = NSTemporaryDirectory() as NSString
        let filePath = (path as NSString).appendingPathComponent((self as NSString).lastPathComponent)
        return filePath
    }
}
